<template>
  <div>
    <el-tree ref="myForm" node-key="id" :data="list" :props="{label:'name'}" show-checkbox default-expand-all check-strictly />

    <el-row>
      <el-button type="primary" @click="hSubmit">确认</el-button>
      <el-button type="primary">取消</el-button>
    </el-row>
  </div>

</template>

<script>
import { getPermissionList } from '@/api/permissions'
import { transDataToTreeData } from '@/utils/index'
import { getRolesId, assignPrem } from '@/api/settings'
export default {
  props: {
    curId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      list: []
    }
  },
  created() {
    this.loadPermissionList()
  },
  methods: {
    async loadPermissionList() {
      // 获取角色列表
      const res = await getPermissionList()
      console.log(res, 'getPermissionList')
      // 获取角色详情
      const res1 = await getRolesId(this.curId)
      console.log(res1, getRolesId)
      this.$refs.myForm.setCheckedKeys(res1.data.permIds)

      this.list = transDataToTreeData(res.data)
    },
    async  hSubmit() {
      const permIds = this.$refs.myForm.getCheckedKeys()
      console.log(permIds, 'permIds')
      const res = await assignPrem({ id: this.curId, permIds: permIds })
      console.log(res, 'assignPrem')
      this.$emit('success')
    }
  }
}
</script>
